package cn.xshi.sys.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import cn.xshi.sys.model.SysCompany;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.util.StringUtil;
import cn.xshi.sys.service.SysCompanyService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Desc 公司信息
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/sysCompany")
@Api(value = "平台公司信息API",tags = "平台公司信息API",description = "平台公司信息API")
public class SysCompanyController extends BaseAction {

	@Resource
	private SysCompanyService sysCompanyService;

	/**
	 * 查询公司信息
	 * @return
	 */
	@ApiOperation(value="查询公司信息", notes="查询公司信息")
	@GetMapping(value="/get/singel")
	@Auth(value = "/sysCompany/get/singel",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<SysCompany> getSysCompany(){
		Map<String, Object> condition = new HashMap<String, Object>();
		List<SysCompany> sysCompanyList = sysCompanyService.getSysCompanyListByCondition(condition);
		SysCompany sysCompany = new SysCompany();
		if(!sysCompanyList.isEmpty()){
			sysCompany = sysCompanyList.get(0);
		}
		return outDataStr(sysCompany);
	}

	/**
	 * 添加或修改
	 * @param sysCompany
	 */
	@ApiOperation(value="添加或修改公司信息", notes="添加或修改公司信息")
	@PostMapping(value="/addOrUpdate")
	public BaseResult addOrUpdateSysCompany(@RequestBody SysCompany sysCompany){
		int i = 0;
		if(null != sysCompany){
			if(!StringUtil.isEmpty(sysCompany.getId())){
				i = sysCompanyService.updateSysCompany(sysCompany);
			}else{
				sysCompany.setId(toUUID());
				i= sysCompanyService.addSysCompany(sysCompany);
			}
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation(value="删除公司信息", notes="删除公司信息")
	@DeleteMapping(value="/delete")
	public BaseResult delSysCompany(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i= sysCompanyService.delSysCompany(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
